package christ.mmd.bl.reading;

public class Verse {
	int mParagraphFrom = 0;
	int mVerseFrom = 0;
	int mParagraphTo = 0;
	int mVerseTo = 0;

	public Verse(int paragraph, int verseFrom, int verseTo) {
		this(paragraph, verseFrom, paragraph, verseTo);
	}

	public Verse(int paragraphFrom, int verseFrom, int paragraphTo, int verseTo) {
		mParagraphFrom = paragraphFrom;
		mParagraphTo = paragraphTo;
		mVerseFrom = verseFrom;
		mVerseTo = verseTo;
	}

	@Override
	public String toString() {
		return toString(0);
	}

	public String toString(int prevParagraph) {
		StringBuffer sb = new StringBuffer();
		boolean includeParagraphs = true;
		if (prevParagraph != 0) {
			if (mParagraphFrom == prevParagraph) {
				includeParagraphs = false;
				sb.append(". ");
			} else {
				sb.append("; ");
			}
		}
		if (includeParagraphs) {
			sb.append(mParagraphFrom);
			sb.append(",");
		}

		sb.append(mVerseFrom);
		sb.append("-");
		if (includeParagraphs && (mParagraphFrom != mParagraphTo)) {
			sb.append(mParagraphTo);
			sb.append(",");
		}
		sb.append(mVerseTo);
		return sb.toString();
	}
}
